package niuke;

import java.util.ArrayList;

/**
 * description:
 * author:张腾
 * date:2021-06-28
 */

/**
 * 给定一个数组和滑动窗口的大小，找出所有滑动窗口里数值的最大值。
 * 窗口大于数组长度的时候，返回空
 */
public class NC82 {
    public static void main(String[] args) {
        System.out.println(new NC82().maxInWindows(new int[]{10, 14, 12, 11}, 5));
    }
    public ArrayList<Integer> maxInWindows(int [] num, int size) {
        ArrayList<Integer> list = new ArrayList<>();
        if (size<1 || size>num.length) return list;
        int offset = 0;
        while (offset+size<=num.length){
            int max = Integer.MIN_VALUE;
            for (int i = 0; i < size; i++) {
                if (num[offset+i]>max) max = num[offset+i];
            }
            list.add(max);
            offset++;
        }
        return list;
    }
}
